Skip to content

Conversation

@vinocher-bc
Copy link
Contributor

@vinocher-bc vinocher-bc commented Jun 18, 2024

When the 'Enter' key is pressed, format the previous line because the user has usually moved to a new empty line. This is the most common scenario.

Also, format only the previous line instead of the entire document for better performance and because formatting the entire doc may conflict with "editor.formatOnSaveMode": "modifications" (See Only format modified text.)

Previously, the entire document was formatted if the new line was non-empty.

@vinocher-bc
Copy link
Contributor Author

@vknabel, @MahdiBM, please review if possible. Thanks.

@vknabel
Copy link
Owner

vknabel commented Jun 22, 2024

Great start! Though when having the following code, formatting lead to losing the indentation:

SomeType()
    .doSomething (  )

// was formatted to
SomeType()
.doSomething()

I suppose for non-empty lines we should advance the range to the first non-whitespace character.

@vknabel vknabel requested review from MahdiBM and vknabel June 22, 2024 10:04
Copy link
Collaborator

@MahdiBM MahdiBM left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some suggestions, other than @vknabel 's.

@vinocher-bc
Copy link
Contributor Author

vinocher-bc commented Jun 24, 2024

Great start! Though when having the following code, formatting lead to losing the indentation:

SomeType()
    .doSomething (  )

// was formatted to
SomeType()
.doSomething()

I suppose for non-empty lines we should advance the range to the first non-whitespace character.

This looks like a swiftformat issue -- I don't think there is a workaround. Added it to the end of nicklockwood/SwiftFormat#1738. I don't think we can make this change in the extension until swiftformat fixes the corresponding issue, otherwise it may be too disruptive for users.

@MahdiBM
Copy link
Collaborator

MahdiBM commented Jun 24, 2024

@vinocher-bc ppssibly we can see how many spaces are at beginning of the line before format, and add them back after the format too each new line of the formatted text?

@vknabel
Copy link
Owner

vknabel commented Nov 21, 2024

Is this ready to merge now as nicklockwood/SwiftFormat#1738 has been resolved?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants